﻿/*
 * Author:xmfdsh 11届网络部--邓世豪
 * DataTime：2014-6-9
 * Copyright © 2014 大学生勤工助学服务队 Powered by xmfdsh & 四小狼工作室.
 * 版权所有，违者必究
 */
using QGZX.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Mvc;

namespace QGZX.Logic.QGOA
{
    public class WorkPlaceController : Controller
    {
        #region 排班系统收集 页面 + ActionResult SchedulingSystem()
        /// <summary>
        /// 排班系统收集 页面
        /// </summary>
        /// <returns></returns>
        public ActionResult SchedulingSystem()
        {
            MODEL.qgzx_config config = OperateContext.Current.BLLSession.Iqgzx_configBLL.GetListBy(x => x.SystemName == "系统设置").FirstOrDefault();
            int num = Convert.ToInt32(config.Help);
            string[] name = config.Remark.Split(',');
            ViewBag.num = num;
            ViewBag.name = name;
            MODEL.qgoa_user u = (MODEL.qgoa_user)Session["user"];
            ViewBag.u = u;
            if (config.Version.Equals("0"))
                return OperateContext.Current.RedirectAjax("err", "系统尚未开启", null, "");
            MODEL.qgzx_config model = OperateContext.Current.BLLSession.Iqgzx_configBLL.GetListBy(x => x.SystemName != null).FirstOrDefault();
            ViewBag.configModel = model;
            return View();
        } 
        #endregion

        
        public ActionResult MutualEvaluation()
        {
            MODEL.qgzx_config config = OperateContext.Current.BLLSession.Iqgzx_configBLL.GetListBy(x => x.SystemName == "系统设置").FirstOrDefault();
            if (config.About.Equals("0"))
                return OperateContext.Current.RedirectAjax("err", "系统尚未开启", null, "/QGOA/User/Index");

            ViewBag.list = OperateContext.Current.BLLSession.Iqgoa_userBLL.GetListBy(x => x.Id != null);
            MODEL.qgzx_config model = OperateContext.Current.BLLSession.Iqgzx_configBLL.GetListBy(x => x.SystemName != null).FirstOrDefault();
            ViewBag.configModel = model;
            return View();
        }

        public ActionResult Comment()
        {
            int Id = Convert.ToInt32(Request["id"]);
            MODEL.qgoa_user user = OperateContext.Current.BLLSession.Iqgoa_userBLL.GetListBy(x => x.Id == Id).FirstOrDefault();
            MODEL.qgoa_user u = (MODEL.qgoa_user)Session["user"];
            ViewBag.u = u;
            ViewBag.user = user;
            MODEL.qgzx_config model = OperateContext.Current.BLLSession.Iqgzx_configBLL.GetListBy(x => x.SystemName != null).FirstOrDefault();
            ViewBag.configModel = model;
            return View();
        }

        public ActionResult ActionMutualuation()
        {
            string dowhat =Request.Form["dowhat"];

            if (dowhat.Equals("add_comment"))
            {
                string Comment = Request.Form["Comment"];
                int SenderUid = Convert.ToInt32(Request.Form["SenderUid"]);
                int ReceiverUid = Convert.ToInt32(Request.Form["ReceiverUid"]);

                MODEL.qgoa_message msg = new MODEL.qgoa_message();
                msg.SenderUid = SenderUid;
                msg.ReceiverUid = ReceiverUid;
                msg.Message = Comment;
                msg.DateTime = System.DateTime.Now;
                OperateContext.Current.BLLSession.Iqgoa_messageBLL.Add(msg);
                Response.Write("success");
            }
            return null;
        }

        public ActionResult GetMessage()
        {
            MODEL.qgzx_config model = OperateContext.Current.BLLSession.Iqgzx_configBLL.GetListBy(x => x.SystemName != null).FirstOrDefault();
            ViewBag.configModel = model;
            MODEL.qgoa_user me = (MODEL.qgoa_user)Session["user"];
            List<MODEL.qgoa_message> list = OperateContext.Current.BLLSession.Iqgoa_messageBLL.GetListBy(x => x.ReceiverUid == me.Id).ToList();
            ViewBag.list = list;
            return View();
        }

        #region Action处理方法集合 + ActionResult Action()
        /// <summary>
        /// Action处理方法集合
        /// </summary>
        /// <returns></returns>
        public ActionResult Action()
        {
            string time = Request.Form["check"];

            int Id = Convert.ToInt32(Request.Form["Id"]);
            //MODEL.qgoa_user user = OperateContext.Current.BLLSession.Iqgoa_userBLL.GetListBy(x => x.Number == number).FirstOrDefault();
            MODEL.qgoa_user user = (MODEL.qgoa_user)Session["user"];
            user.Json = time;
            OperateContext.Current.BLLSession.Iqgoa_userBLL.ModifyBy(user, x => x.Id == Id, "Json");
            return OperateContext.Current.RedirectAjax("ok", "操作成功", null, "/QGOA/User/Index");
        } 
        #endregion
    }
}
